home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / dev / mui / MCC_SpeedBar.lha / MCC_SpeedBar / Developer / C / Examples / demo6.c < prev    next >
C/C++ Source or Header  |  2002-06-13  |  11KB  |  293 lines

  1.  
  2. #include <proto/exec.h>
  3. #include <proto/dos.h>
  4. #include <proto/datatypes.h>
  5. #include <proto/muimaster.h>
  6. #include <clib/alib_protos.h>
  7. #include <mui/SpeedBar_mcc.h>
  8. #include <mui/SpeedBarCfg_mcc.h>
  9. #include <datatypes/pictureclass.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12.  
  13. /***********************************************************************/
  14.  
  15. long __stack = 8192;
  16. struct Library *DataTypesBase;
  17. struct Library *MUIMasterBase;
  18.  
  19. /***********************************************************************/
  20.  
  21. #ifndef MAKE_ID
  22. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  23. #endif
  24.  
  25. /***********************************************************************/
  26.  
  27. struct MUIS_SpeedBar_Button buttons[] =
  28. {
  29.     {0, "_Get", "Get the disc.", 0, NULL},
  30.     {1, "Sa_ve", "Save the disc.", 0, NULL},
  31.     {2, "_Stop", "Stop the connection.", 0, NULL},
  32.     {MUIV_SpeedBar_Spacer},
  33.     {3, "_Disc", "Disc page.", 0, NULL},
  34.     {4, "_Matches", "Matches page.", 0, NULL},
  35.     {5, "_Edit", "Edit page.", 0, NULL},
  36.     {MUIV_SpeedBar_End},
  37. };
  38.  
  39. /***********************************************************************/
  40.  
  41. static Object *
  42. loadDTBrush(struct MyBrush *brush,STRPTR file)
  43. {
  44.     struct BitMapHeader *bmh;
  45.     register Object     *dto;
  46.  
  47.     if (!(dto = NewDTObject(file,DTA_GroupID,GID_PICTURE,PDTA_Remap,FALSE,PDTA_DestMode,PMODE_V42,TAG_DONE)) ||
  48.         !(DoMethod(dto,DTM_PROCLAYOUT,NULL,1)) ||
  49.         !(GetDTAttrs(dto,PDTA_DestBitMap,&brush->BitMap,PDTA_CRegs,&brush->Colors,PDTA_BitMapHeader,&bmh,TAG_DONE)==3))
  50.     {
  51.         if (dto)
  52.         {
  53.             DisposeDTObject(dto);
  54.             dto = NULL;
  55.         }
  56.         brush->BitMap = NULL;
  57.     }
  58.     else
  59.     {
  60.         brush->Width  = bmh->bmh_Width;
  61.         brush->Height = bmh->bmh_Height;
  62.     }
  63.  
  64.     return dto;
  65. }
  66.  
  67. /***********************************************************************/
  68.  
  69. Object *
  70. buttonObject(STRPTR label)
  71. {
  72.     Object *obj;
  73.  
  74.     if (obj = MUI_MakeObject(MUIO_Button,label))
  75.         set(obj,MUIA_CycleChain,TRUE);
  76.  
  77.     return obj;
  78. }
  79.  
  80. /***********************************************************************/
  81.  
  82. Object *
  83. checkmarkObject(STRPTR key)
  84. {
  85.     Object *obj;
  86.  
  87.     if (obj = MUI_MakeObject(MUIO_Checkmark,key))
  88.         set(obj,MUIA_CycleChain,TRUE);
  89.  
  90.     return obj;
  91. }
  92.  
  93. /***********************************************************************/
  94.  
  95. Object *
  96. cycleObject(STRPTR *labels,STRPTR key)
  97. {
  98.     Object *obj;
  99.  
  100.     if (obj = MUI_MakeObject(MUIO_Cycle,key,labels))
  101.         set(obj,MUIA_CycleChain,TRUE);
  102.  
  103.     return obj;
  104. }
  105.  
  106. /***********************************************************************/
  107.  
  108. #define TEMPLATE "STRIP,NUMBUTTON/N"
  109.  
  110. STRPTR positions[] =
  111. {
  112.     "Bottom",
  113.     "Top",
  114.     "Right",
  115.     "Left",
  116.     NULL
  117. };
  118.  
  119. int
  120. main(int argc,char **argv)
  121. {
  122.     struct RDArgs   *ra;
  123.     LONG            arg[2] = {0};
  124.     int             res;
  125.  
  126.     if (ra = ReadArgs(TEMPLATE,arg,NULL))
  127.     {
  128.         if (DataTypesBase = OpenLibrary("datatypes.library",37))
  129.         {
  130.             if (MUIMasterBase = OpenLibrary("muimaster.library",19))
  131.             {
  132.                 struct MyBrush                  stripBrush;
  133.                 Object                          *dto, *app, *win, *sb, *pos, *cfg, *update, *c0, *c1, *c2, *c3, *c4, *c5;
  134.                 struct MUIS_SpeedBarCfg_Config  c = {MUIV_SpeedBar_ViewMode_TextGfx, MUIV_SpeedBarCfg_Borderless|MUIV_SpeedBarCfg_Sunny};
  135.                 STRPTR                          stripName;
  136.  
  137.                 stripName = arg[0] ? (char *)arg[0] : "PROGDIR:Pics/Main.toolbar";
  138.  
  139.                 if (!(dto = loadDTBrush(&stripBrush,stripName)))
  140.                     printf("%s: warning can't load '%s'\n",argv[0],stripName);
  141.  
  142.                 if (app = ApplicationObject,
  143.                         MUIA_Application_Title,         "SpeedBar Demo6",
  144.                         MUIA_Application_Version,       "$VER: SpeedBarDemo6 14.4 (13.6.2002)",
  145.                         MUIA_Application_Copyright,     "Copyright 1999-2002 by Alfonso Ranieri",
  146.                         MUIA_Application_Author,        "Alfonso Ranieri <alforan@tin.it>",
  147.                         MUIA_Application_Description,   "Speed(Bar|Button|BarCfg).mcc test",
  148.                         MUIA_Application_Base,          "SPEEDBARTEST",
  149.  
  150.                         SubWindow, win = WindowObject,
  151.                             MUIA_Window_ID,             MAKE_ID('M','A','I','N'),
  152.                             MUIA_Window_Title,          "SpeedBar Demo6",
  153.  
  154.                             WindowContents, VGroup,
  155.  
  156.                                 Child, HGroup,
  157.                                     GroupFrame,
  158.                                     Child, sb = SpeedBarObject,
  159.                                         MUIA_Group_Horiz,               TRUE,
  160.                                         MUIA_SpeedBar_Borderless,       TRUE,
  161.                                         MUIA_SpeedBar_Sunny,            TRUE,
  162.                                         MUIA_SpeedBar_Buttons,          buttons,
  163.                                         MUIA_SpeedBar_StripUnderscore,  TRUE,
  164.                                         MUIA_SpeedBar_EnableUnderscore, TRUE,
  165.                                         MUIA_SpeedBar_BarSpacer,        TRUE,
  166.                                         MUIA_SpeedBar_StripBrush,       &stripBrush,
  167.                                         MUIA_SpeedBar_StripButtons,     arg[1] ? (*((ULONG *)arg[1])) : 14,
  168.                                     End,
  169.                                     Child, HSpace(0),
  170.                                 End,
  171.  
  172.                                 Child, VGroup,
  173.                                     GroupFrameT("Appareance"),
  174.                                     Child, VSpace(0),
  175.                                     Child, cfg = SpeedBarCfgObject,
  176.                                         MUIA_SpeedBarCfg_Config, &c,
  177.                                     End,
  178.                                     Child, HGroup,
  179.                                         Child, Label2("Label position"),
  180.                                         Child, pos = cycleObject(positions,NULL),
  181.                                     End,
  182.                                     Child, VSpace(0),
  183.                                     Child, update = buttonObject("_Update"),
  184.                                 End,
  185.  
  186.                                 Child, VGroup,
  187.                                     GroupFrameT("Disable"),
  188.                                     Child, VSpace(0),
  189.                                     Child, HGroup,
  190.                                         Child, HSpace(0),
  191.                                         Child, RowGroup(2),
  192.                                             Child, Label1("Disable _0"),
  193.                                             Child, c0 = checkmarkObject("0"),
  194.                                             Child, Label1("Disable _1"),
  195.                                             Child, c1 = checkmarkObject("1"),
  196.                                             Child, Label1("Disable _2"),
  197.                                             Child, c2 = checkmarkObject("2"),
  198.                                             Child, Label1("Disable _3"),
  199.                                             Child, c3 = checkmarkObject("3"),
  200.                                             Child, Label1("Disable _4"),
  201.                                             Child, c4 = checkmarkObject("4"),
  202.                                             Child, Label1("Disable _5"),
  203.                                             Child, c5 = checkmarkObject("5"),
  204.                                         End,
  205.                                         Child, HSpace(0),
  206.                                     End,
  207.                                     Child, VSpace(0),
  208.                                 End,
  209.  
  210.                             End,
  211.                         End,
  212.                     End)
  213.                 {
  214.                     ULONG sigs = 0, id;
  215.  
  216.                     DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,MUIV_Notify_Application,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  217.                     DoMethod(update,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,TAG_USER);
  218.  
  219.                     DoMethod(c0,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,sb,5,MUIM_SpeedBar_DoOnButton,0,MUIM_Set,MUIA_Disabled,MUIV_TriggerValue);
  220.                     DoMethod(c1,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,sb,5,MUIM_SpeedBar_DoOnButton,1,MUIM_Set,MUIA_Disabled,MUIV_TriggerValue);
  221.                     DoMethod(c2,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,sb,5,MUIM_SpeedBar_DoOnButton,2,MUIM_Set,MUIA_Disabled,MUIV_TriggerValue);
  222.                     DoMethod(c3,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,sb,5,MUIM_SpeedBar_DoOnButton,4,MUIM_Set,MUIA_Disabled,MUIV_TriggerValue);
  223.                     DoMethod(c4,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,sb,5,MUIM_SpeedBar_DoOnButton,5,MUIM_Set,MUIA_Disabled,MUIV_TriggerValue);
  224.                     DoMethod(c5,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,sb,5,MUIM_SpeedBar_DoOnButton,6,MUIM_Set,MUIA_Disabled,MUIV_TriggerValue);
  225.  
  226.                     set(win,MUIA_Window_Open,TRUE);
  227.  
  228.                     while ((id = DoMethod(app,MUIM_Application_NewInput,&sigs))!=MUIV_Application_ReturnID_Quit)
  229.                     {
  230.                         if (id==TAG_USER)
  231.                         {
  232.                             struct MUIS_SpeedBarCfg_Config  *c;
  233.                             ULONG                           p;
  234.  
  235.                             get(cfg,MUIA_SpeedBarCfg_Config,&c);
  236.                             get(pos,MUIA_Cycle_Active,&p);
  237.  
  238.                             SetAttrs(sb,MUIA_SpeedBar_ViewMode,c->ViewMode,
  239.                                         MUIA_SpeedBar_Borderless,c->Flags & MUIV_SpeedBarCfg_Borderless,
  240.                                         MUIA_SpeedBar_RaisingFrame,c->Flags & MUIV_SpeedBarCfg_Raising,
  241.                                         MUIA_SpeedBar_SmallImages,c->Flags & MUIV_SpeedBarCfg_SmallButtons,
  242.                                         MUIA_SpeedBar_Sunny,c->Flags & MUIV_SpeedBarCfg_Sunny,
  243.                                         MUIA_SpeedBar_LabelPosition,p,
  244.                                         TAG_DONE);
  245.                         }
  246.  
  247.                         if (sigs)
  248.                         {
  249.                             sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  250.                             if (sigs & SIGBREAKF_CTRL_C) break;
  251.                         }
  252.                     }
  253.  
  254.                     MUI_DisposeObject(app);
  255.  
  256.                     res = RETURN_OK;
  257.                 }
  258.                 else
  259.                 {
  260.                     printf("%s: can't create application\n",argv[0]);
  261.                     res = RETURN_FAIL;
  262.                 }
  263.  
  264.                 if (dto) DisposeDTObject(dto);
  265.                 CloseLibrary(MUIMasterBase);
  266.             }
  267.             else
  268.             {
  269.                 printf("%s: Can't open muimaster.library ver 19 or higher\n",argv[0]);
  270.                 res = RETURN_ERROR;
  271.             }
  272.  
  273.             CloseLibrary(DataTypesBase);
  274.         }
  275.         else
  276.         {
  277.             printf("%s: can't open dtatypes.library ver 37 or higher\n",argv[0]);
  278.             res = RETURN_ERROR;
  279.         }
  280.  
  281.         FreeArgs(ra);
  282.     }
  283.     else
  284.     {
  285.         PrintFault(IoErr(),argv[0]);
  286.         return RETURN_FAIL;
  287.     }
  288.  
  289.     return res;
  290. }
  291.  
  292. /***********************************************************************/
  293.